/**
 * 项目名称:
 *
 * @Author: 夏国倩
 * @Date: 2023/9/20 15:19
 * @Copyright
 */
package Collection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class Collection6 {
    /*
    将酒店员工、厨师、服务员、经理 分别存储到3个集合中
    定义方法，可以同时遍历3个集合，遍历3个集合的同时，可以调用work（）
     */
    public static void main(String[] args) {
        Collection<ChuShi> array = new ArrayList<>();
        array.add(new ChuShi("张三","后厨1"));
        array.add(new ChuShi("李四","后厨2"));

        Collection<FuWuYuan> array1 = new ArrayList<>();
        array1.add(new FuWuYuan("王五","服务部1"));
        array1.add(new FuWuYuan("李明","服务部2"));

        Collection<JingLi> array2 = new ArrayList<>();
        array2.add(new JingLi("赵四","董事会1"));
        array2.add(new JingLi("张萌","董事会2"));

        iterator(array);
        iterator(array1);
        iterator(array2);
    }

    /*
    定义方法，同时遍历3个集合，同时调用work()
     */
    private static void iterator(Collection<? extends Employee> coll) {
        Iterator<? extends Employee> it = coll.iterator();
        while (it.hasNext()) {
            //it.next()获取到的数据类型是Employee
            Employee employee=it.next();
            employee.work();
        }
    }
}

class Employee {
    private String name;
    private String dept;

    public Employee(String name, String dept) {
        this.name = name;
        this.dept = dept;
    }

    public void work() {
        System.out.println(this.dept + "的" + this.name + "正在工作.....");
    }
}
    class ChuShi extends Employee {
        public ChuShi(String name, String dept) {
            super(name, dept);
        }
    }

    class FuWuYuan extends Employee {
        public FuWuYuan(String name, String dept) {
            super(name, dept);
        }
    }

    class JingLi extends Employee {
        public JingLi(String name, String dept) {
            super(name, dept);
        }
    }

